package cn.juque.singleton.internalstatic;

/**
 * @author juque
 * @version 1.0.0
 * <ul>
 *     <li>内部静态类</li>
 * </ul>
 * @date 2023-06-13 00:00:52
 **/
public class Singleton {

    private Singleton() {
    }

    public static Singleton getInstance() {
        return SingletonHolder.INSTANCE;
    }

    public void hello() {
        System.out.println("你好呀！我是通过内部静态类初始化哦！");
        System.out.println("------>>>>我饿汉模式可不一样！");
        System.out.println("------>>>>饿汉模式是类加载时就会被实例化，");
        System.out.println("------>>>>而我只有getInstance方法被调用时候，才会装载内部静态类，从而实例化！");
    }

    private static class SingletonHolder {
        private static final Singleton INSTANCE = new Singleton();
    }
}
